/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Figures;

import java.awt.Point;
import java.util.ArrayList;

/**
 *
 * @author Macias
 */
public class Bishop extends Figures{
    int white ;
    public Bishop(boolean isWh,Point loc){
        location = loc;
        isWhite = isWh;

        if(isWhite) white=1; else white=0; //int representing boolean
    }
    @Override
    public ArrayList<Point> checkPossibleMoves(char [][] board) {
        ArrayList<Point> possibleMoves = new ArrayList();
        boolean dirNW,dirNE,dirSW,dirSE;
        dirNW=dirNE=dirSW=dirSE = true;
        int i= 1;
        while(dirNW || dirNE || dirSW || dirSE){         //we are searching possible moves in all directions if at least one is free we continue searching

            if(dirNW){
                if((location.x-i)>=0 && (location.y-i)>=0 ){
                    if( board[location.x-i][location.y-i]=='0' ){    // location is empty
                        possibleMoves.add(new Point(location.x-i,location.y-i));
                    } else
                        if(board[location.x-i][location.y-i]>=(65+32*white) && board[location.x-i][location.y-i]<=(90+32*white)){ //we found oponents figure
                            possibleMoves.add(new Point(location.x-i,location.y-i));
                            dirNW=false; //we cannot search further - this figure cannot jump over other figures
                        }
                    
                    else    dirNW=false;
                    
                }   else dirNW=false;
            }

            if(dirNE){
                if((location.x+i)<=7 && (location.y-i)>=0 ){
                    if( board[location.x+i][location.y-i]=='0' ){    // location is empty
                        possibleMoves.add(new Point(location.x+i,location.y-i));
                    } else
                        if(board[location.x+i][location.y-i]>=(65+32*white) && board[location.x+i][location.y-i]<=(90+32*white)){ //we found oponents figure
                            possibleMoves.add(new Point(location.x+i,location.y-i));
                            dirNE=false; //we cannot search further - this figure cannot jump over other figures
                        }

                    else    dirNE=false;

                }   else dirNE=false;
            }

            if(dirSW){
                if( (location.x-i)>=0 && (location.y+i)<=7 ){
                    if( board[location.x-i][location.y+i]=='0' ){    // location is empty
                        possibleMoves.add(new Point(location.x-i,location.y+i));
                    } else
                        if(board[location.x-i][location.y+i]>=(65+32*white) && board[location.x-i][location.y+i]<=(90+32*white)){ //we found oponents figure
                            possibleMoves.add(new Point(location.x-i,location.y+i));
                            dirSW=false; //we cannot search further - this figure cannot jump over other figures
                        }

                    else    dirSW=false;

                }   else dirSW=false;
            }

            if(dirSE){
                if((location.x+i)<=7 && (location.y+i)<=7 ){
                    if( board[location.x+i][location.y+i]=='0' ){    // location is empty
                        possibleMoves.add(new Point(location.x+i,location.y+i));
                    } else
                        if(board[location.x+i][location.y+i]>=(65+32*white) && board[location.x+i][location.y+i]<=(90+32*white)){ //we found oponents figure
                            possibleMoves.add(new Point(location.x+i,location.y+i));
                            dirSE=false; //we cannot search further - this figure cannot jump over other figures
                        }

                    else    dirSE=false;

                }   else dirSE=false;
            }


            i++;
        }
        
        return possibleMoves;
    }

    @Override
    public int getType(){
        if(isWhite) return 66;
        else return 98;

    }
}
